﻿#coding=utf-8
from distutils.core import setup
import py2exe
import sys
import os


if len(sys.argv) == 1:
    sys.argv.append("py2exe")

class Target:
    def __init__(self, **kw):
        self.__dict__.update(kw)
        self.version = "0.96"
        self.company_name = "No Company"
        self.copyright = "copyright 龙之吻"
        self.name = "cndevOE"

manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="5.0.0.0"
    processorArchitecture="x86"
    name="%(prog)s"
    type="win32"
/>
<description>%(prog)s Program</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
'''
RT_MANIFEST = 24

def GetImg():
    s = []
    path = os.path.dirname(__file__)
    if os.path.isfile(path):
        path = os.path.dirname(os.path.abspath(path))+"img"
    print path
    for root, dirs, files in os.walk(path):
        for f in files:
            fname, ext = os.path.splitext(f)
            if ext in ('.bmp', '.gif', '.png',".ico"):
                s.append("img/"+f)
    return s
                
cndevOE = Target(
    description = "cndev Offline Explorer",
    script = "cndevOE.py",
    other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="cndevOE"))],
    icon_resources = [(1, "img/plone.ico")],
    dest_base = "cndevOE")
setup(
    options = {"py2exe": {"compressed": 1,
                          "optimize": 2,
                          "bundle_files": 1}}, 
    zipfile = None,
    windows = [cndevOE],
    data_files = [
            ('', ['CHANGES.txt', 'INFO.txt',"INSTALL.txt","LICENSE.txt","README.txt","TODO.txt"]),
            ("img",GetImg()),
            ],
    )
